package com.kdg.thread;

/**
 * Created by kong on 2018/6/11.
 */
public class ThreadLocalTest {

    static ThreadLocal<Integer> threadLocal = new ThreadLocal(){
        @Override
        protected Object initialValue() {
            return 3;
        }
    };

    static class Test implements Runnable{

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName()+" is starting...");
            Integer id = threadLocal.get();
            int s = id + 1;
            threadLocal.set(s);
            System.out.println(Thread.currentThread().getName() + " thread local value is "
                + threadLocal.get());
        }
    }

    public static void main(String[] args) {
        for(int i=0;i<3;i++){
            new Thread(new Test()).start();
        }
    }
}
